//
//  ReportCardListVC.m
//  jzyParents
//
//  Created by 任辰东 on 2022/8/20.
//

#import "ReportCardListVC.h"
#import "ReportCardTCell.h"
#import "ReportCardVC.h"
#import "ReportApis.h"
#import "KemuDetailPageVC.h"

@interface ReportCardListVC ()

@end

@implementation ReportCardListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"成绩报告";

    [self setupEstimatedRowHeight:120 cellClasses:@[[ReportCardTCell class]]];
    
    [self beginRefresh];
}

-(void)requestDataWithOffset:(NSInteger)offset success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"id_card"] = [GVUserDefaults standardUserDefaults].id_card;
//    params[@"id_card"] = @"410802200912100020";
    params[@"page"] = @(offset);
    params[@"page_size"] = @(10);
    
    DLog(@"params === %@",params);
    WeakSelf
    [self showLoadingHUDWithMessage:nil];
    [ReportApis ctb_Xq_KaoshiListRequestWithParams:params SuccessBlock:^(NSNumber *code, NSString *msg, id responseData) {
        StrongSelf
        [self hideLoadingHUD];
    
        NSArray *data = [ReportCardModel mj_objectArrayWithKeyValuesArray:responseData];
        success(data);
        [self addEmptyView];
        
    } FailureBlock:^(NSNumber *code, NSString *msg) {
        StrongSelf
        [self showWarningHUDWithMessage:msg completion:NULL];
    }];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReportCardModel *model;
    if (indexPath.row < self.dataSourceArr.count) {
        model = self.dataSourceArr[indexPath.row];
    }
    
    ////1.联考;2.考试;3.练习;4.作业
//    if (model.is_liankao.integerValue == 1) {
//        ReportCardVC *cardVC = [[ReportCardVC alloc]initWithModel:model];
//        [self.navigationController pushViewController:cardVC animated:YES];
//    }else{
//        KemuDetailPageVC *pageVC = [[KemuDetailPageVC alloc]initWithModel:model WithKemuID:@"0"];
//        [self.navigationController pushViewController:pageVC animated:YES];
//    }
    
    ReportCardVC *cardVC = [[ReportCardVC alloc]initWithModel:model];
    [self.navigationController pushViewController:cardVC animated:YES];

}

-(void)addEmptyView
{
    if (IsEmpty(self.dataSourceArr)) {
        [RCDEmptyView addEmptyWithStyle:EmptyViewStyleCommon onView:self.myTableView position:EmptyViewPositionCenter clickCallBack:nil];
    }else{
        [RCDEmptyView removeFromParentView:self.myTableView];
    }
}


@end
